package ${javaPackage}<#if javaPackage?? && javaPackage != ''>.</#if>controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.util.oConvertUtils;
import ${javaPackage}<#if javaPackage?? && javaPackage != ''>.</#if>model.${modelName};
import ${javaPackage}<#if javaPackage?? && javaPackage != ''>.</#if>service.${modelName}Service;
import java.util.Date;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @Description: <#if tableComment?? && tableComment != ''>${tableComment}</#if>
 * @Author: ${author}
 * @Date: ${.now?string["yyyy-MM-dd"]}
 * @Version: ${version}
 */
@Slf4j
@Api(tags = "<#if tableComment?? && tableComment != ''>${tableComment}</#if>")
@RestController
@RequestMapping("/${modelName?uncap_first}")
public class ${modelName}Controller extends JeecgController<${modelName}, ${modelName}Service> {

    @Autowired
    private ${modelName}Service ${modelName?uncap_first}Service;

    /**
     * 分页列表查询
     *
     * @param ${modelName?uncap_first}
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "<#if tableComment?? && tableComment != ''>${tableComment}-</#if>分页列表查询", notes = "权限码：${javaPackage}:${modelName}:list")
    @GetMapping(value = "/list")
    @RequiresPermissions("${javaPackage}:${modelName}:list")
    public Result<?> queryPageList(${modelName} ${modelName?uncap_first},
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   @RequestParam(name = "searchCount", defaultValue = "true") Boolean searchCount,
                                   HttpServletRequest req) {
        QueryWrapper<${modelName}> queryWrapper = QueryGenerator.initQueryWrapper(${modelName?uncap_first}, req.getParameterMap());
        Page<${modelName}> page = new Page<${modelName}>(pageNo, pageSize, searchCount);
        IPage<${modelName}> pageList = ${modelName?uncap_first}Service.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param ${modelName?uncap_first}
     * @return
     */
    @ApiOperation(value = "<#if tableComment?? && tableComment != ''>${tableComment}-</#if>添加", notes = "权限码：${javaPackage}:${modelName}:add")
    @PostMapping(value = "/add")
    @RequiresPermissions("${javaPackage}:${modelName}:add")
    public Result<?> add(@RequestBody ${modelName} ${modelName?uncap_first}) {
        ${modelName?uncap_first}Service.save(${modelName?uncap_first});
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param ${modelName?uncap_first}
     * @return
     */
    @ApiOperation(value = "<#if tableComment?? && tableComment != ''>${tableComment}-</#if>编辑", notes = "权限码：${javaPackage}:${modelName}:edit")
    @PostMapping(value = "/edit")
    @RequiresPermissions("${javaPackage}:${modelName}:edit")
    public Result<?> edit(@RequestBody ${modelName} ${modelName?uncap_first}) {
        ${modelName?uncap_first}Service.updateById(${modelName?uncap_first});
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "<#if tableComment?? && tableComment != ''>${tableComment}-</#if>通过id删除", notes = "权限码：${javaPackage}:${modelName}:delete")
    @PostMapping(value = "/delete")
    @RequiresPermissions("${javaPackage}:${modelName}:delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        ${modelName?uncap_first}Service.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "<#if tableComment?? && tableComment != ''>${tableComment}-</#if>批量删除", notes = "权限码：${javaPackage}:${modelName}:deleteBatch")
    @PostMapping(value = "/deleteBatch")
    @RequiresPermissions("${javaPackage}:${modelName}:deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.${modelName?uncap_first}Service.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功！");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "<#if tableComment?? && tableComment != ''>${tableComment}-</#if>通过id查询", notes = "权限码：${javaPackage}:${modelName}:queryById")
    @GetMapping(value = "/queryById")
    @RequiresPermissions("${javaPackage}:${modelName}:queryById")
    public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
        ${modelName} ${modelName?uncap_first} = ${modelName?uncap_first}Service.getById(id);
        return Result.OK(${modelName?uncap_first});
    }

    /**
     * 导出excel
     *
     * @param request
     * @param ${modelName?uncap_first}
     */
    @ApiOperation(value = "<#if tableComment?? && tableComment != ''>${tableComment}-</#if>导出excel", notes = "权限码：${javaPackage}:${modelName}:exportXls")
    @RequestMapping(value = "/exportXls")
    @RequiresPermissions("${javaPackage}:${modelName}:exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ${modelName} ${modelName?uncap_first}) {
        return super.exportXls(request, ${modelName?uncap_first}, ${modelName}.class, "<#if tableComment?? && tableComment != ''>${tableComment}</#if>");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @ApiOperation(value = "<#if tableComment?? && tableComment != ''>${tableComment}-</#if>通过excel导入数据", notes = "权限码：${javaPackage}:${modelName}:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    @RequiresPermissions("${javaPackage}:${modelName}:importExcel")
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ${modelName}.class);
    }
}
